/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Tbv_maquinaDAOImpl implements orm.dao.Tbv_maquinaDAO {
	public Tbv_maquina loadTbv_maquinaByORMID(int ma_id_maquina) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_maquinaByORMID(session, ma_id_maquina);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina getTbv_maquinaByORMID(int ma_id_maquina) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_maquinaByORMID(session, ma_id_maquina);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina loadTbv_maquinaByORMID(int ma_id_maquina, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_maquinaByORMID(session, ma_id_maquina, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina getTbv_maquinaByORMID(int ma_id_maquina, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_maquinaByORMID(session, ma_id_maquina, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina loadTbv_maquinaByORMID(PersistentSession session, int ma_id_maquina) throws PersistentException {
		try {
			return (Tbv_maquina) session.load(orm.Tbv_maquina.class, new Integer(ma_id_maquina));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina getTbv_maquinaByORMID(PersistentSession session, int ma_id_maquina) throws PersistentException {
		try {
			return (Tbv_maquina) session.get(orm.Tbv_maquina.class, new Integer(ma_id_maquina));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina loadTbv_maquinaByORMID(PersistentSession session, int ma_id_maquina, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_maquina) session.load(orm.Tbv_maquina.class, new Integer(ma_id_maquina), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina getTbv_maquinaByORMID(PersistentSession session, int ma_id_maquina, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_maquina) session.get(orm.Tbv_maquina.class, new Integer(ma_id_maquina), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina[] listTbv_maquinaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_maquinaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina[] listTbv_maquinaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_maquinaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina[] listTbv_maquinaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_maquina as Tbv_maquina");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Tbv_maquina[]) list.toArray(new Tbv_maquina[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina[] listTbv_maquinaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_maquina as Tbv_maquina");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Tbv_maquina[]) list.toArray(new Tbv_maquina[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina loadTbv_maquinaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_maquinaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina loadTbv_maquinaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_maquinaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina loadTbv_maquinaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tbv_maquina[] tbv_maquinas = listTbv_maquinaByQuery(session, condition, orderBy);
		if (tbv_maquinas != null && tbv_maquinas.length > 0)
			return tbv_maquinas[0];
		else
			return null;
	}
	
	public Tbv_maquina loadTbv_maquinaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tbv_maquina[] tbv_maquinas = listTbv_maquinaByQuery(session, condition, orderBy, lockMode);
		if (tbv_maquinas != null && tbv_maquinas.length > 0)
			return tbv_maquinas[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTbv_maquinaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_maquinaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_maquinaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_maquinaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_maquinaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_maquina as Tbv_maquina");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_maquinaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_maquina as Tbv_maquina");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina createTbv_maquina() {
		return new orm.Tbv_maquina();
	}
	
	public boolean save(orm.Tbv_maquina tbv_maquina) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().saveObject(tbv_maquina);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Tbv_maquina tbv_maquina) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().deleteObject(tbv_maquina);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_maquina tbv_maquina)throws PersistentException {
		try {
			if(tbv_maquina.getTbv_tipo_maquinatm_id_tipo_maquina() != null) {
				tbv_maquina.getTbv_tipo_maquinatm_id_tipo_maquina().tbv_maquina.remove(tbv_maquina);
			}
			
			if(tbv_maquina.getTbv_tipo_serviciots_id_tipo_servicio() != null) {
				tbv_maquina.getTbv_tipo_serviciots_id_tipo_servicio().tbv_maquina.remove(tbv_maquina);
			}
			
			if(tbv_maquina.getTbv_clientecl_id_cliente() != null) {
				tbv_maquina.getTbv_clientecl_id_cliente().tbv_maquina.remove(tbv_maquina);
			}
			
			if(tbv_maquina.getTbv_caja_monedacm_id_caja_monedas() != null) {
				tbv_maquina.getTbv_caja_monedacm_id_caja_monedas().tbv_maquina.remove(tbv_maquina);
			}
			
			if(tbv_maquina.getTbv_caja_billetecb_id_caja_billetes() != null) {
				tbv_maquina.getTbv_caja_billetecb_id_caja_billetes().tbv_maquina.remove(tbv_maquina);
			}
			
			if(tbv_maquina.getTbv_comunaco_id_comuna() != null) {
				tbv_maquina.getTbv_comunaco_id_comuna().tbv_maquina.remove(tbv_maquina);
			}
			
			if(tbv_maquina.getTbv_rutaru_id_ruta() != null) {
				tbv_maquina.getTbv_rutaru_id_ruta().tbv_maquina.remove(tbv_maquina);
			}
			
			orm.Tbv_bitacora_maquina[] lTbv_bitacora_maquinas = tbv_maquina.tbv_bitacora_maquina.toArray();
			for(int i = 0; i < lTbv_bitacora_maquinas.length; i++) {
				lTbv_bitacora_maquinas[i].setTbv_maquinama_id_maquina(null);
			}
			orm.Tbv_maquina_tbv_producto[] lTbv_maquina_tbv_productos = tbv_maquina.tbv_maquina_tbv_producto.toArray();
			for(int i = 0; i < lTbv_maquina_tbv_productos.length; i++) {
				lTbv_maquina_tbv_productos[i].setTbv_maquinama_id_maquina(null);
			}
			orm.Tbv_maquina_tbv_ruta_programada[] lTbv_maquina_tbv_ruta_programadas = tbv_maquina.tbv_maquina_tbv_ruta_programada.toArray();
			for(int i = 0; i < lTbv_maquina_tbv_ruta_programadas.length; i++) {
				lTbv_maquina_tbv_ruta_programadas[i].setTbv_maquinama_id_maquina(null);
			}
			return delete(tbv_maquina);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_maquina tbv_maquina, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(tbv_maquina.getTbv_tipo_maquinatm_id_tipo_maquina() != null) {
				tbv_maquina.getTbv_tipo_maquinatm_id_tipo_maquina().tbv_maquina.remove(tbv_maquina);
			}
			
			if(tbv_maquina.getTbv_tipo_serviciots_id_tipo_servicio() != null) {
				tbv_maquina.getTbv_tipo_serviciots_id_tipo_servicio().tbv_maquina.remove(tbv_maquina);
			}
			
			if(tbv_maquina.getTbv_clientecl_id_cliente() != null) {
				tbv_maquina.getTbv_clientecl_id_cliente().tbv_maquina.remove(tbv_maquina);
			}
			
			if(tbv_maquina.getTbv_caja_monedacm_id_caja_monedas() != null) {
				tbv_maquina.getTbv_caja_monedacm_id_caja_monedas().tbv_maquina.remove(tbv_maquina);
			}
			
			if(tbv_maquina.getTbv_caja_billetecb_id_caja_billetes() != null) {
				tbv_maquina.getTbv_caja_billetecb_id_caja_billetes().tbv_maquina.remove(tbv_maquina);
			}
			
			if(tbv_maquina.getTbv_comunaco_id_comuna() != null) {
				tbv_maquina.getTbv_comunaco_id_comuna().tbv_maquina.remove(tbv_maquina);
			}
			
			if(tbv_maquina.getTbv_rutaru_id_ruta() != null) {
				tbv_maquina.getTbv_rutaru_id_ruta().tbv_maquina.remove(tbv_maquina);
			}
			
			orm.Tbv_bitacora_maquina[] lTbv_bitacora_maquinas = tbv_maquina.tbv_bitacora_maquina.toArray();
			for(int i = 0; i < lTbv_bitacora_maquinas.length; i++) {
				lTbv_bitacora_maquinas[i].setTbv_maquinama_id_maquina(null);
			}
			orm.Tbv_maquina_tbv_producto[] lTbv_maquina_tbv_productos = tbv_maquina.tbv_maquina_tbv_producto.toArray();
			for(int i = 0; i < lTbv_maquina_tbv_productos.length; i++) {
				lTbv_maquina_tbv_productos[i].setTbv_maquinama_id_maquina(null);
			}
			orm.Tbv_maquina_tbv_ruta_programada[] lTbv_maquina_tbv_ruta_programadas = tbv_maquina.tbv_maquina_tbv_ruta_programada.toArray();
			for(int i = 0; i < lTbv_maquina_tbv_ruta_programadas.length; i++) {
				lTbv_maquina_tbv_ruta_programadas[i].setTbv_maquinama_id_maquina(null);
			}
			try {
				session.delete(tbv_maquina);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Tbv_maquina tbv_maquina) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().refresh(tbv_maquina);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Tbv_maquina tbv_maquina) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().evict(tbv_maquina);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_maquina loadTbv_maquinaByCriteria(Tbv_maquinaCriteria tbv_maquinaCriteria) {
		Tbv_maquina[] tbv_maquinas = listTbv_maquinaByCriteria(tbv_maquinaCriteria);
		if(tbv_maquinas == null || tbv_maquinas.length == 0) {
			return null;
		}
		return tbv_maquinas[0];
	}
	
	public Tbv_maquina[] listTbv_maquinaByCriteria(Tbv_maquinaCriteria tbv_maquinaCriteria) {
		return tbv_maquinaCriteria.listTbv_maquina();
	}
}
